import axios from 'axios'
export const baseURL = process.env.NODE_ENV === 'production'? 'http://47.99.51.143:9000' : 'http://localhost:9000'
const request = axios.create({
  baseURL,
  timeout: 5000
})

/* request.interceptors.request.use(
  config => {
    config.headers['Content-Type'] = 'application/json;charset=UTF-8';
    const user=localStorage.getItem('user');
    if(user){
      config.headers['token'] = JSON.parse(user).token;
    }
    return config
  }, 
  error => {
    console.log(error)
    return Promise.reject(error)
  }
) */

request.interceptors.response.use(
  response => {
    let res = response.data;
    if (typeof res === 'string') {
      res = res ? JSON.parse(res) : res
    }
    return res;
  },
  error => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)

export default request;